﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Zor_Modes;
using Zor_Tools;
using Zor_Bll;
using Newtonsoft.Json.Linq;

namespace Zor_API.Controllers
{
    public class AppUsersController : ApiController
    {
       
        /// <summary>
        /// 添加App用户
        /// </summary>
        /// <param name="aus"></param>
        /// <returns></returns>
        [HttpPost]
        public BaseAnswer InserAppUsers([FromBody]AppUsers aus)
        {
            aus.AppUser_LoginPassword = Encryption.GetMd5Str(aus.AppUser_LoginPassword);
            return AppUsers_Bll.InserAppUsers(aus);
        }


         /// <summary>
        /// 判断用户是否已注册过(身份证或者手机号)
        /// </summary>
        /// <param name="aus"></param>
        /// <returns></returns>
        [HttpPost]
        public BaseAnswer AppUsersByLoginName([FromBody]AppUsers aus)
        {
            return AppUsers_Bll.GetAppUsersByLoginName(aus);
        }

         /// <summary>
        /// App用户登录
        /// </summary>
        /// <param name="us"></param>
        /// <returns></returns>
        [HttpPost]
        public BaseAnswer AppUserByLoginNameAndPass([FromBody]AppUsers aus)
        {
            aus.AppUser_LoginPassword = Encryption.GetMd5Str(aus.AppUser_LoginPassword);
            return AppUsers_Bll.GetAppUserByLoginNameAndPass(aus);
        }

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="users"></param>
        /// <returns></returns>
         [HttpPost]
        public HttpResponseMessage UpdatePassWord([FromBody]AppUsers aus)
        {
            BaseAnswer bar = new BaseAnswer();
            aus.AppUser_LoginPassword = Encryption.GetMd5Str(aus.AppUser_LoginPassword);
            bar = AppUsers_Bll.UpdateAppUsersPassword(aus);

            HttpResponseMessage result = new HttpResponseMessage
            {
                Content = new StringContent(bar.ToJson(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json")
            };
            return result;
        }
    }
}
